<template>
	<view>
		<button type="default" @click="handleCfy">转录分类</button>
		<button type="default" @click="handleGoods">转录商品</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				obj: [],
				goods:[]
			};
		},
		methods: {
			handleCfy() {
				uni.request({
					url: 'https://h5.mcake.com/api/5e90690f0e270d04?cityId=110',
					method: 'GET',
					header: {
						'access-token': 'd3485da4958e29c581cae6175580919a',
						'version': 'v1.0'
					},
					success: (res) => {
						let {data} = res.data
						let batchObj = {"requests": []}
						data.forEach(item => {
							batchObj.requests.push({
								"method": "POST",
								"path": "/1.1/classes/classify",
								"body": item
							})

						})

						this.obj = batchObj
						// this.$post('/1.1/batch',batchObj)
						// console.log('已执行');
						console.log(this.obj);
						uni.request({
							url: 'https://se1zcx96.lc-cn-n1-shared.com/1.1/batch',
							method: 'POST',
							header: {
								'X-LC-Id': 'SE1zCX96WxeRzvNyhm5rdVMI-gzGzoHsz',
								'X-LC-Key': '92BR3Wc2daMq9gUWib15J6Q5',
								'Content-Type': 'application/json',
							},
							data: this.obj,
							success: (res) => {
								console.log('提交的数据');
								console.log(res);

							}
						})
					}
				})
			},
			handleGoods() {
				uni.request({
						url: 'https://h5.mcake.com/api/0434b49d1ac28f9d?cityId=110&page=2&bid=6',
						method: 'GET',
						header: {
							'access-token': 'd3485da4958e29c581cae6175580919a',
							'version': 'v1.0'
						},
						success: (res) => {
							console.log(res);
							let { list } = res.data.data
							let batchObj = {"requests": []}
							list.forEach(item => {
								batchObj.requests.push({
									"method": "POST",
									"path": "/1.1/classes/goods",
									"body": item
								})
							})
							this.goods = batchObj
							console.log(this.goods);
							uni.request({
								url: 'https://se1zcx96.lc-cn-n1-shared.com/1.1/batch',
								method: 'POST',
								header: {
									'X-LC-Id': 'SE1zCX96WxeRzvNyhm5rdVMI-gzGzoHsz',
									'X-LC-Key': '92BR3Wc2daMq9gUWib15J6Q5',
									'Content-Type': 'application/json',
								},
								data: this.goods,
								success: (res) => {
									console.log('提交的数据');
									console.log(res);
								}
							})
						}
					})
				
			}

		}
	}
</script>

<style lang="scss">

</style>
